package com.niit.az;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Avator extends Activity {

    private GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_avator);

        gridView = (GridView)findViewById(R.id.homeworkgridview);

        SimpleAdapter simpleAdapter = new SimpleAdapter(Avator.this, getData(),
                R.layout.activity_avator_list,new String[]{"image","imagename"},new int[]{R.id.image,R.id.imagename});

        gridView.setAdapter(simpleAdapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(Avator.this,
                        "您选择了第 "+(position+1)+"个",Toast.LENGTH_LONG).show();
                Intent myIntent=new Intent(Avator.this,Personal.class);
                myIntent.putExtra("position",position+"0");
                startActivity(myIntent);
            }

        });

    }

    public List<Map<String,Object>> getData(){
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("image",R.drawable.avatar1);
        map.put("imagename","img1");
        list.add(map);
        Map<String,Object> map1 = new HashMap<String,Object>();
        map1.put("image",R.drawable.avatar2);
        map1.put("imagename","img2");
        list.add(map1);
        Map<String,Object> map2 = new HashMap<String,Object>();
        map2.put("image",R.drawable.avatar3);
        map2.put("imagename","img3");
        list.add(map2);
        Map<String,Object> map3 = new HashMap<String,Object>();
        map3.put("image", R.drawable.avatar4);
        map3.put("imagename","img4");
        list.add(map3);
        Map<String,Object> map4 = new HashMap<String,Object>();
        map4.put("image",R.drawable.avatar5);
        map4.put("imagename","img5");
        list.add(map4);
        Map<String,Object> map5 = new HashMap<String,Object>();
        map5.put("image",R.drawable.avatar6);
        map5.put("imagename","img6");
        list.add(map5);
        Map<String,Object> map6 = new HashMap<String,Object>();
        map6.put("image",R.drawable.avatar7);
        map6.put("imagename","img7");
        list.add(map6);
        Map<String,Object> map7 = new HashMap<String,Object>();
        map7.put("image",R.drawable.avatar8);
        map7.put("imagename","img8");
        list.add(map7);
        Map<String,Object> map8 = new HashMap<String,Object>();
        map8.put("image",R.drawable.avatar9);
        map8.put("imagename","img9");
        list.add(map8);
        Map<String,Object> map9 = new HashMap<String,Object>();
        map9.put("image",R.drawable.avatar10);
        map9.put("imagename","img10");
        list.add(map9);
        return list;
    }
}
